/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package session;

import entities.Cliente;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author sflesca
 */
@Stateless
public class ClienteFacade extends AbstractFacade<Cliente> {
    @PersistenceContext(unitName = "Negozio2014Web-JSFPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ClienteFacade() {
        super(Cliente.class);
    }
    
        public Cliente findCliente(String cognome, String nome) {
        List<Cliente> clienti = getEntityManager().createNamedQuery("findAllClienteByCognomeNome").setParameter("cognome", cognome).setParameter("nome", nome).getResultList();
        if((clienti==null)||clienti.size()!=1)
            return null;
        return clienti.get(0);
    }
}
